home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ahoy 1987 November
/
Ahoy_Magazine_87-11_1987_Double_L.d64
/
Amazement 64
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
5KB
|
169 lines
10 rem ---------------------------------
11 rem amazement
12 rem rupert report #47
13 rem
14 rem c-128 / c-64
15 rem c-64 users see notes at line 2000
16 rem
17 rem ---------------------------------
20 rem ================ initialization =
30 print"[147]"
40 false=0 : true=not false
50 nc=100 :rem # cells
60 sq=int(sqr(nc)+.5) :rem width of square
70 dim mv(nc,1),ms(nc,4) :rem moves and maze structure
80 dim x(nc),y(nc) :rem screen positions
90 gosub 1320 :rem get maze structure
100 gosub 1500 :rem get screen positions
110 gosub 1700 :rem draw screen
120 dly=100 :rem move delay
130 for n=1 to nc : if ms(n,0)=3 then c=n : n=nc
140 next n :rem find starting cell
150 if c=0 then print"no starting cell" : end
160 rem ==================== main loop =
170 gosub 300 :rem pick move
180 gosub 400 :rem check move
190 gosub 900 :rem update screen
200 if not xit and not nosoln then 170
210 a=0:b=21:ch$="":gosub 2200
220 if nosoln then print"no solution" : end
230 gosub 3010 :rem retrace solution
240 a=0:b=21:ch$="":gosub 2200
250 end
260 rem ================================
300 rem -------------------- pick move -
310 gdmove=true :rem assume good
320 mv(c,0)=mv(c,0)+1 :rem increment move direction; c=current cell
330 dir=mv(c,0) :rem current direction
340 return
350 rem
400 rem ------------------- check move -
410 bkup=false :rem assume no backup
420 if dir>4 then gosub 800 : goto 490 : rem must back up
430 nxtcell=ms(c,dir) :rem next cell #
440 cs=ms(nxtcell,0) :rem cell status
450 rem cs=0,2,3 invalid move
460 rem cs=1 valid move
470 rem cs=4 end of maze
480 on cs+1 gosub 600,500,600,600,700
490 return :rem to main loop
500 rem ------------------- valid move -
510 mv(c,0)=dir :rem set fwd link
520 mv(nxtcell,1)=c :rem set back link
530 ms(nxtcell,0)=2 :rem status=used
540 c=nxtcell :rem current cell
550 return
600 rem ----------------- invalid move -
610 gdmove=false
620 if ms(c,0)=3 and mv(c,0)=4 then nosoln=true
630 return
700 rem ------------------------- done -
710 mv(c,0)=dir :rem set fwd link
720 mv(nxtcell,1)=c :rem set back link
730 c=nxtcell
740 xit=true
750 return
800 rem ----------------------- backup -
810 restart=false :rem assume no restart
820 nxtcell=mv(c,1) :rem use back link
830 mv(c,0)=0 :rem restore fwd link
840 ms(c,0)=1 :rem set status to available
850 c0=c :rem save old cell #
860 c=nxtcell
870 bkup=true
880 if ms(c,0)=3 then restart=true : if mv(c,0)=4 then nosoln=true
890 return
900 rem ---------------- screen update -
910 c$="o"
920 if not gdmove then goto 1060
930 if xit then c$="e" : goto 1000
940 if not bkup then goto 1000
950 if nosoln or restart then c$="s"
960 rem restore cell c0 to unused
970 a=x(c0):b=y(c0):ch$=" ":gosub 2200
980 a=x(c0):b=y(c0):ch$="*":gosub 2200
990 rem move cursor to cell c
1000 for n=1 to 2
1010 a=x(c):b=y(c):ch$=" ": gosub 2200
1020 for p=1 to dly : next
1030 a=x(c):b=y(c):ch$=c$ : gosub 2200
1040 for p=1 to dly : next
1050 next n
1060 return :rem to main
1070 rem ===============================
1100 rem maze data structure
1110 rem
1120 rem ms(c,n): c=cell #, n=0-4
1130 rem n=0: current cell status
1140 rem 0=no access,1=available,2=used
1150 rem 3=start, 4=end
1160 rem n=1-4: cell #'s in directions
1170 rem 1-4 from cell c;
1180 rem 1=up, 2=rt, 3=down, 4=left
1190 rem -------------------------------
1200 rem ms(c,0) cell status data
1210 data 1,0,0,0,1,1,1,1,1,1
1220 data 1,1,1,1,0,0,1,0,1,0
1230 data 1,0,0,1,1,0,1,0,1,0
1240 data 1,0,0,0,1,0,1,0,1,0
1250 data 0,1,1,1,1,0,1,0,1,0
1260 data 1,1,0,0,1,0,1,0,1,0
1270 data 1,0,0,0,0,0,1,0,1,1
1280 data 1,0,0,0,0,0,1,0,0,1
1290 data 3,1,1,1,1,1,1,0,1,1
1300 data 1,0,0,0,0,4,0,1,1,0
1310 rem read cell status data
1320 for n=1 to nc : read ms(n,0) : next
1330 rem calc adjacent cell #'s
1340 for n=1 to nc : mod%=n-sq*int(n/sq+.01)
1350 ms(n,1)=n-sq : if n<sq+1 then ms(n,1)=0
1360 ms(n,2)=n+1 : if mod%=0 then ms(n,2)=0
1370 ms(n,3)=n+sq : if n>nc-sq then ms(n,3)=0
1380 ms(n,4)=n-1 : if mod%=1 then ms(n,4)=0
1390 next n
1400 return
1500 rem --- get cell screen locations -
1510 row=1
1520 col=1
1530 for c=1 to nc step sq
1540 for n=c to c+sq-1
1550 y(n)=row
1560 x(n)=col : col=col+3
1570 next n
1580 row=row+2 : col=1
1590 next c
1600 return
1700 rem ----------------- draw screen -
1710 print chr$(147)
1720 for n=1 to nc
1730 c$="." : if ms(n,0)=1 then c$="*"
1740 if ms(n,0)=3 then c$="s"
1750 if ms(n,0)=4 then c$="e"
1760 a=x(n):b=y(n):ch$=c$ : gosub 2200
1770 next
1780 return
2000 rem =============================
2010 rem >>> notes for c-64 users:
2020 rem change the 'char'
2030 rem statements in lines 210, 240,
2040 rem 970, 980, 1010, 1030, & 1760
2100 rem to the following:
2110 rem 210 a=0:b=21:ch$="":gosub 2200
2120 rem 240 a=0:b=21:ch$="":gosub 2200
2130 rem 970 a=x(c0):b=y(c0):ch$=" ":gosub 2200
2140 rem 980 a=x(c0):b=y(c0):ch$="*":gosub 2200
2150 rem 1010 a=x(c):b=y(c):ch$=" ": gosub 2200
2160 rem 1030 a=x(c):b=y(c):ch$=c$ : gosub 2200
2170 rem 1760 a=x(n):b=y(n):ch$=c$ : gosub 2200
2180 rem =============================
2190 rem c-64 only >>>>>>>>
2200 poke 214,b-1 : print
2210 poke 211,a : print ch$ : return
2220 rem =============================
3000 rem --- retrace the solution ----
3010 c$="-"
3020 c=mv(c,1) :if ms(c,0)<>3 then gosub 1000 : goto 3020
3030 c$="+"
3040 c=ms(c,mv(c,0)) :if ms(c,0)<>4 then gosub 1000 : goto 3040
3050 return